package com.transsion.clouddemo.core.config

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

/**
 * 实时日志的数据VM
 */
object LogViewModel : ViewModel() {

    //显示的最大行数
    const val MAX_LINES_NUMBER = 100

    //若超过最大行数，动态删除的行数
    const val MAX_REMOVE_LINES = 10

    val _addLogEntries = MutableLiveData<List<LogEntry>>()
    val addLogEntries: LiveData<List<LogEntry>> get() = _addLogEntries

    fun updateLogEntry() {

    }

    fun addLogEntry(newLogEntry: LogEntry) {
        val updatedList = _addLogEntries.value.orEmpty().toMutableList()
        updatedList.add(newLogEntry)
        _addLogEntries.value = updatedList
    }

    fun updateLogEntries(newLogEntries: List<LogEntry>) {
//        if (_addLogEntries.value!!.size >= MAX_LINES_NUMBER) {
//            _addLogEntries.value?.let{
//                _addLogEntries.value= it.filterIndexed{ index, _->index>=MAX_REMOVE_LINES }
//            }
//        }
        _addLogEntries.postValue(newLogEntries)
    }


}
